//    Copyright 2009-2011 Ateeq Sharfuddin, Xiaofan Feng.
//    This file is part of Project Viatei.
//
//    Project Viatei is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Project Viatei is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Project Viatei.  If not, see <http://www.gnu.org/licenses/>.

#include "delta1.h"

namespace boyermoore
{
	std::vector<wordi_t> delta1(const std::string & pattern)
	{
		const std::string::size_type m = pattern.length();
		
		// create the delta1 vector, initially setting all elements to
		// pattern.length().
		std::vector<wordi_t> badshift(ALPHABET_SIZE, m);
		
		// update table for characters in the pattern
		for ( std::string::size_type i = 0 ; i < m - 1 ; ++i )
			badshift[ (std::string::size_type)pattern[ i ] ] = m - i - 1;
		
		return badshift;
	}

	std::vector<wordi_t> delta1(const unsigned char * pattern, word_t const length)
	{
		const word_t m = length;
		
		std::vector<wordi_t> badshift(ALPHABET_SIZE, m);
		
		for ( word_t i = 0 ; i < m - 1 ; ++i )
			badshift[ pattern[ i ] ] = m - i - 1;
		
		return badshift;
	}
	
}